import { request } from 'umi';
import { MenuTreeResponse,getMenuParams,GetMenuListResponse,MenuInfoSaveRequestParams,GetMenuDetailsResponse,MenuDeleteRequestParams} from './data'

//菜单查询列表
export async function queryMenuList(options?: {
    [key: string]: any;
}){
    return  request<AircasKB.ResponseType<GetMenuListResponse[]>>(
        `/aircaskb/sys/menu/findList`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

//获取系统菜单树
export async function getSystemMenuTreeData(options?: {
    [key: string]: any;
}){
    return  request<AircasKB.ResponseType<MenuTreeResponse[]>>(
        `/aircaskb/sys/menu/getMenuTree`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

// 查看角色拥有的菜单的列表
export async function getMenuTreeByRole(
    body: getMenuParams, 
    options?: { [key: string]: any }){
    const { roleId } = body;
    return  request<AircasKB.ResponseType<MenuTreeResponse[]>>(
        `/aircaskb/sys/menu/roleId?roleId=${roleId}`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

// 保存角色信息
export async function MenuInfoSaveRequest(body:MenuInfoSaveRequestParams, options?: {[key: string]: any}){
    return request(
        `/aircaskb/sys/menu/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

// 删除角色
export async function DeleteMenuRequest(
    body: MenuDeleteRequestParams, 
    options?: { [key: string]: any }){
    const { id } = body;
    return request<AircasKB.ResponseType<GetMenuDetailsResponse>>(
        `/aircaskb/sys/menu/delete/?id=${id}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}